package com.thwcompany.mpdemo.controller;
import com.thwcompany.mpdemo.param.UserParam;
import com.thwcompany.mpdemo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: tenghuawei-demo
 * @author: tenghw
 * @create: 2024-02-24 16:27
 * @Version 1.0
 * @description:
 **/
@Slf4j
@RestController
@RequestMapping("/mp")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getList")
    public Object getList(UserParam userParam){
        if(StringUtils.isEmpty(userParam.getCurrentPage()) || StringUtils.isEmpty(userParam.getSizePage())){
            throw new IllegalArgumentException("params is null");
        }
        log.info("分页参数为：{}",userParam);
        return userService.getList(userParam);
    }

    @GetMapping("/getUserByIdAndCity")
    public Object getUserByIdAndCity(UserParam userParam){
        if(StringUtils.isEmpty(userParam.getCurrentPage()) || StringUtils.isEmpty(userParam.getSizePage())){
            throw new IllegalArgumentException("分页参数 is null");
        }
        if(StringUtils.isEmpty(userParam.getId()) || StringUtils.isEmpty(userParam.getCity())){
            throw new IllegalArgumentException("查询参数 is null");
        }
        log.info("入参为：{}",userParam);
        return userService.getUserByIdAndCity(userParam);
    }
}